package sgbag1.Vues;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.Point2D;

import sgbag1.Noyau.Toboggan;

public class VueToboggan extends VueElement {
    
    private int dimension = 25;
    private Color couleur = new Color(16, 78, 139);
    private Polygon forme;
    private Toboggan toboggan;
    
    public VueToboggan(Toboggan t){
        this(new Point(t.getPosition()));
        toboggan = t;
    }
    
    public VueToboggan(Point p){
        super(p);
        
        calculateForme();
    }
    
    public VueToboggan(){
        this(new Point(0, 0));
    }
    
    public void calculateForme(){
        forme = new Polygon();
        forme.addPoint((int)this.position.getX(), (int)this.position.getY());
        forme.addPoint((int)this.position.getX() + dimension, (int)this.position.getY() - dimension / 2);
        forme.addPoint((int)this.position.getX() + dimension, (int)this.position.getY() + dimension / 2);
        
        this.CalculerBoiteEnglobante();
    }
    
    @Override
    public void setTauxConversion(double t){
        super.setTauxConversion(t);
        position = new Point(toboggan.getPosition());
        position.setLocation(position.getX()*tauxConversion, position.getY()*tauxConversion);
        /*position.x *= tauxConversion;
        position.y *= tauxConversion;*/
        calculateForme();
    }
    
    @Override
    public void setDecalage(Point p){
        super.setDecalage(p);
        position.setLocation(position.getX()+decalage.getX(), position.getY()+decalage.getY());
        //position.translate(decalage.x, decalage.y);
        calculateForme();
    }
    
    public Toboggan getObjetNoyau(){
        return toboggan;
    }
    
    @Override
    public void Dessiner(Graphics g){
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        
        g2.setColor(couleur);
        g2.fill(forme);
        
        g2.setColor(new Color(255,215,0));
        g2.drawString("" + toboggan.getId(), position.x + 15, position.y + 2);
        super.Dessiner(g);
        
    }
    
    @Override
    public void CalculerBoiteEnglobante(){
        boiteEnglobante = forme.getBounds();
    }
}
